package com.kunya.cms.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.kunya.cms.po.SellerInfo;
import com.kunya.cms.service.ISellerInfoService;
import com.kunya.common.util.RedisPoolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
 * 商家域名信息
 */
@WebListener
public class SellerInfoListener implements ServletContextListener {
    @Autowired
    private ISellerInfoService sellerInfService;


    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("监听销毁");
    }


    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("监听开始加载");
        //查询全部的商家信息
        List<SellerInfo> sellerInfoList = sellerInfService.findAllCmsSellerInfo();
        System.out.println("监听开始加载" + sellerInfoList.toString());
        //获取redis 中的信息
        for (SellerInfo sellerInfo:sellerInfoList){
            RedisPoolUtil.set(sellerInfo.getDomainName(),sellerInfo.getUserId().toString());
        }
        System.out.println("监听初始化完毕");

    }


}